function toggleContent(id) {
	$("#divContent_" + id).toggle("fast");
}
function confLayout(pageId) {
	var url = "iframe:jsp/portlet/editportal.jsp?pageId=" + pageId;
	var opt = {
		title : "编辑页面布局",
		width : 370,
		height : 240,
		buttons : {}
	};
	getTopWin(window).openjBox(url, opt, 'show-layout-module', window);
}
function hiddenIt(id) {
	$.ajax({
				type : "POST",
				url : "/bsm/portlet/portal!delete.action", // 请求的action
				data : "pageId=" + portalPage + "&confId=" + id, // 传的参数
				dataType : 'json',
				async : false,
				success : function(data) {
					$("#divWrap_" + id).detach();
					dropendCallBack();
				}
			});

}
function dropendCallBack() {
	var tds = $('.portal-col');
	var len = tds.length;
	var arr = $('.portal');
	var arr = new Array();
	for (var i = 0; i < tds.length; i++) {
		var box = $(tds[i]).children(".portal")
		for (var j = 0; j < box.length; j++) {
			boxId = box[j].id;
			boxId = boxId.substring(boxId.indexOf("_") + 1);
			arr.push(boxId + "#" + j + "#" + i);
		}
	}
	$.ajax({
				type : "POST",
				url : "/bsm/portlet/portal!saveSeq.action", // 请求的action
				data : "pageId=" + portalPage + "&args=" + arr, // 传的参数
				dataType : 'json',
				success : function(data) {

				}
			});

}


reloadPage = function() {
	alert('reload');
	//window.location.reload();
}
function addComp() {
	var url = "iframe:jsp/portlet/showjspmodule.jsp?page=" + portalPage;
	var opt = {
		title : "添加页面组件",
		width : 240,
		height : 475,
		buttons : {}
	};
	getTopWin(window).openjBox(url, opt, 'show-jsp-module', window);
}
function showParamPage(confId, paramPage, modeleTitle) {
	
	if(paramPage=='null'){
		getTopWin(window).getMessageBox().alert("该组件没有可定制的参数。","提示");
		return;
	}
	var url = "iframe:jsp/portlet/params/" + paramPage + ".jsp?confId="
			+ confId;
	var opt = {
		title : modeleTitle==null?"页面参数设置":"【"+modeleTitle+"】参数设置",
		width : 450,
		height : 240,
		buttons : {}
	};
	getTopWin(window).openjBox(url, opt, 'show-jsp-params', window);
}

$(document).ready(function() {
			var dropx, dropTitle, curCol = null, curCols = [];
			$('.portal').bind('dragstart', function(event) {
						if ($(event.target).is('.handle')) {
							var w = $(this).width();
							var h = $(this).height();
							$('body').selectable(false);
							oldCol = curCol = $(this).parent('td.portal-col');
							dropTitle = $(event.target).css('cursor', 'move');
							dropx = $('<div class="box"><br/><div>').css({
										border : '1px dashed #666',
										height : h
									});
							$(this).before(dropx);
							$(this).css({
										position : 'absolute',
										width : w,
										height : h,
										opacity : 0.5
									}).removeClass('portal');
						} else {
							return false;
						}
					}).bind('drag', function(e) {
						$(this).css({
									top : e.offsetY,
									left : e.offsetX
								});
						if (curCol == null)
							return;
						var insert = false;
						if (curCols.length > 0) {
							for (var i = 0; i < curCols.length; i++) {
								var $this = $(curCols[i]);
								var oft = $this.offset();
								var h = $this.outerHeight();
								if (e.offsetY < (h / 2 + oft.top)) {
									$this.before(dropx);
									insert = true;
									break;
								}
							}
						}
						if (curCols.length == 0 || !insert) {
							curCol.append(dropx);
						}
					}).bind('dragend', function(event) {
						// dropTitle.css('cursor', 'move');
						dropx.hide();
						dropx.before($(this));
						$(this).css({
									position : 'static',
									width : 'auto',
									height : 'auto',
									opacity : 1
								}).addClass("portal");
						dropx.remove();
						$('body').selectable(true);
						// 保存至数据库中
						dropendCallBack();
					});

			$('.portal-col').bind('dropstart', function(event) {
						curCol = $(this).css({
									background : ''
								});
						curCols = $(this).find('.portal');
					}).bind('drop', function(event) {

					}).bind('dropend', function() {
						$(this).css({
									background : '#fff'
								})

					});

			$.fn.selectable = function(bool) {
				$(this).each(function(i, elem) {
							// var elem = $(n).dom;
							elem.unselectable = bool ? "off" : "on"; // IE
							elem.onselectstart = function() {
								return bool;
							}; // IE
							if (elem.style)
								elem.style.MozUserSelect = bool ? "" : "none"; // FF
						});
			};

		});
// $(window).unload( function () { alert("Bye now!"); } );

